
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.jdom2.Content;
import org.jdom2.Content.CType;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;
//读取xml注释
public class RunJdom {
	public static void main(String[] args) throws Exception {

		HashMap toolsMap = new HashMap();
		File file = new File("pom.xml");
		SAXBuilder sb = new SAXBuilder();
		Document doc = sb.build(file);
		// 构造文档对象
		Element root = doc.getRootElement(); // 获取根元素HD
		for (Iterator iterator = root.getChildren().iterator(); iterator.hasNext();) {
			Element child = (Element) iterator.next(); 
			if (child.getName().equals("dependencies")) { //直接根据名字获取，无法获取子
				for (Iterator iterator2 = child.getChildren().iterator(); iterator2.hasNext();) {
					Element depend = (Element) iterator2.next();
					//System.out.println("依赖" + depend.getName());
				}
				List<Content> contents = child.getContent();
				String url = "";
				String toolName = "";
				for (Content con : contents) {// CType为一个枚举类，一共有七种，其中Comment代表注释
					 System.out.println(con.getCType()+"：\n" + con.getValue());
					if (con.getCType().equals(CType.Comment)) {
						//System.out.println("注释：" + con.getValue());
						url = con.getValue().trim();

					}
					if (con.getCType().equals(CType.Element)) {
						// System.out.println("元素："+con.getValue());
						String[] jar = con.getValue().split("\n");
						//System.out.println(jar[2]);
						toolName = jar[2].trim();
						if (toolName.contains("tool-")) {
							toolsMap.put(toolName, url);
						}
					}
				
				}
			}
		}

		for (Iterator iterator = toolsMap.keySet().iterator(); iterator.hasNext();) {
			String  key = (String ) iterator.next();
			System.out.println(key+"  访问地址 ：" +toolsMap.get(key));
			
		}

	}
}